<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>挂号表</title>

	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

	<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

	<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js">
	</script>
</head>

<body>
   
   <div class="container-fluid">
	<div class="row-fluid">
		<div class="col-md-12">
			<table class="table">
				<thead>
					<tr>
						<th>
							编号
						</th>
						<th>
							学生学号
						</th>
						<th>
							学生姓名
						</th>
						
						<th>
							挂号时间
						</th>
						<th>
							选择就诊
						</th>
						
					</tr>
				</thead>
				<tbody id="waitTab">

				</tbody>
			</table>
		</div>
	</div>
</div>
    
</body>


<script>
	var mydate = new Date().toLocaleDateString();
	console.log(mydate);
	var dc_ID = sessionStorage.getItem("id");


	$(function () {
		$.ajax({
					url:"/clinicReg/dc_id_time",
					type:"POST",
					data: {
						dc_ID:dc_ID,
						time:mydate
					},
					// async: false,

					success: function(result){
						if (result.state == 200){
							var reg = result.data;
							$("#waitTab").html('');
							$.each(reg,function (i) {
								$tr = $("<tr/>");
								$td1 = $("<td/>").text(reg[i].cr_ID);
								$td2 = $("<td/>").text(reg[i].st_ID);
								var studentName;
								$.ajax({
									url:"/student/findByID",
									type:"POST",
									async:false,
									data: {
										st_ID:reg[i].st_ID
									},
									success:function (rst) {
										if(rst.state==200){
											studentName = rst.data.realName;
										}
									}
								});
								$td3 = $("<td/>").text(studentName);
								$td4 = $("<td/>").text(reg[i].time_sc);
								$td5 = $("<button/>").text("就诊").click(function () {

									$.ajax({
										url:"/clinicReg/updateState",
										type:"POST",
										data: {
											cr_ID:reg[i].cr_ID,
											cr_State:2
										},
										success:function (rst) {
											if(rst.state==200){
												console.log(rst)
											}
										}
									});



									window.location.href="/web/doctor/isvisiting.html?cr_id="+reg[i].cr_ID;
								});


								$tr.append($td1).append($td2).append($td3).append($td4).append($td5);

								$("#waitTab").append($tr);
							});


						}


					}
				}
		);
	})
	
</script>
</html>